# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Lars Kanis <lars@greiz-reinsdorf.de>

_realname=freetds
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.1.42
pkgrel=1
pkgdesc="A free implementation of Sybase's DB-Library, CT-Library and ODBC libraries (mingw-w64)"
arch=('any')
url="https://www.freetds.org/"
license=(LGPL2)
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-libiconv")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-libtool")
options=('strip' '!libtool' 'staticlibs')
source=(https://www.freetds.org/files/stable/freetds-${pkgver}.tar.bz2
        0001-Don-t-use-MSYS2-file-libws2_32.patch
        0002-Enable-inet_pton-definition-in-MINGW-i686-build.patch)
sha256sums=('aff70ecdef357b278d117273aab59d63c08a38418794d4fd428eec8fd0b4f00a'
            '27e97c6bab28f00d5f6b00cb4a2f604e9c1919d08ee9fbd12b244461aff9f2d4'
            'f0ac77b00b14db339fb772730ca36c97e8ff69ccfed2fe4291cad6daba47c586')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/0001-Don-t-use-MSYS2-file-libws2_32.patch
  patch -p1 -i ${srcdir}/0002-Enable-inet_pton-definition-in-MINGW-i686-build.patch
}

build() {
  [[ -d "${srcdir}/build-${CARCH}" ]] && rm -rf "${srcdir}/build-${CARCH}"
  mkdir -p "${srcdir}/build-${CARCH}" && cd "${srcdir}/build-${CARCH}"

  ../freetds-${pkgver}/configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --enable-static \
    --enable-shared \
    --with-openssl \
    --enable-sspi

  make
}

package () {
  cd "${srcdir}/build-${CARCH}"
  make DESTDIR="${pkgdir}" install
}
